/*
package org.pearl.oauth2.authorizationserverdemo.oauth2;

import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.security.authentication.AnonymousAuthenticationProvider;
import org.springframework.security.authentication.AuthenticationEventPublisher;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpointHandlerMapping;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.util.ReflectionUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

*/
/**
 * Created by TD on 2021/12/15
 *//*

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
@EnableResourceServer
public class ResourceServerConfiguration extends WebSecurityConfigurerAdapter implements Ordered {

    private int order = 6;

    @Autowired(required = false)
    private TokenStore tokenStore;

    @Autowired(required = false)
    private AuthenticationEventPublisher eventPublisher;

    @Autowired(required = false)
    private Map<String, ResourceServerTokenServices> tokenServices;

    @Autowired
    private ApplicationContext context;

    private List<ResourceServerConfigurer> configurers = Collections.emptyList();

    @Autowired(required = false)
    private AuthorizationServerEndpointsConfiguration endpoints;

    @Override
    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }


    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                // 在内存中创建用户并为密码加密
                .withUser("user").password(new BCryptPasswordEncoder().encode("123456")).roles("USER");
    }


    // 配置认证管理器
    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    */
/**
     * @param configurers the configurers to set
     *//*

    @Autowired(required = false)
    public void setConfigurers(List<ResourceServerConfigurer> configurers) {
        this.configurers = configurers;
    }

    private static class NotOAuthRequestMatcher implements RequestMatcher {

        private FrameworkEndpointHandlerMapping mapping;

        public NotOAuthRequestMatcher(FrameworkEndpointHandlerMapping mapping) {
            this.mapping = mapping;
        }

        @Override
        public boolean matches(HttpServletRequest request) {
            String requestPath = getRequestPath(request);
            for (String path : mapping.getPaths()) {
                if (requestPath.startsWith(mapping.getPath(path))) {
                    return false;
                }
            }
            return true;
        }

        private String getRequestPath(HttpServletRequest request) {
            String url = request.getServletPath();

            if (request.getPathInfo() != null) {
                url += request.getPathInfo();
            }

            return url;
        }

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .formLogin().disable().httpBasic().disable()
                .authorizeRequests()
                .antMatchers("/sdsds/**","/auth/form","loginPage.html").permitAll()
                .anyRequest().authenticated();
    }

    private ResourceServerTokenServices resolveTokenServices() {
        if (tokenServices == null || tokenServices.size() == 0) {
            return null;
        }
        if (tokenServices.size() == 1) {
            return tokenServices.values().iterator().next();
        }
        if (tokenServices.size() == 2) {
            // Maybe they are the ones provided natively
            Iterator<ResourceServerTokenServices> iter = tokenServices.values().iterator();
            ResourceServerTokenServices one = iter.next();
            ResourceServerTokenServices two = iter.next();
            if (elementsEqual(one, two)) {
                return one;
            }
        }
        return context.getBean(ResourceServerTokenServices.class);
    }

    private boolean elementsEqual(Object one, Object two) {
        // They might just be equal
        if (one == two) {
            return true;
        }
        Object targetOne = findTarget(one);
        Object targetTwo = findTarget(two);
        return targetOne == targetTwo;
    }

    private Object findTarget(Object item) {
        Object current = item;
        while (current instanceof Advised) {
            try {
                current = ((Advised) current).getTargetSource().getTarget();
            } catch (Exception e) {
                ReflectionUtils.rethrowRuntimeException(e);
            }
        }
        return current;
    }

}
*/
